import javax.swing.tree.TreeNode;
//二叉搜索树中序遍历有序
class code2 {
    int ret;
    int _k;
    public int kthSmallest(TreeNode root, int k) {
        _k = k;
        dfs(root);
        return ret;
    }

    public void dfs(TreeNode root) {
        if (root == null) {
            return ;
        }
        dfs(root.left);
        if(--_k == 0) {
            ret = root.val;
        }
        dfs(root.right);
    }
}